import {ConfigDataEntity} from "../../../../../generate/entitas";
import BaseGenerator from "../../BaseGenerator";
import {TsGenerator} from "../../../../code_generater/ts/TsGenerator";
import GeneratorDecorator from "../../../GeneratorDecorator";
import MethodInfo from "../../../../MethodInfo";
import {ExcelService} from "../../../../service/ExcelService";
__dirname = __dirname.replace("/dist", "/src")


@GeneratorDecorator.generator("static", "ts")
export default class StaticDecorator extends BaseGenerator{
	type2RowValueListDict : Map<string, Array<any>>

	beforeInit() {
		this.dirPath = __dirname
		this.type2RowValueListDict = new Map<string, Array<any>>()
	}

	onInit() {
		this.rootEntity.onGenerateCodeAction.value.push(this.onWriteCode.bind(this))
		let columnEntityList : Array<ConfigDataEntity> = this.rootEntity.columnEntityList.value
		for (let memberType in this.checkData) {
			for (let i = 0; i < columnEntityList.length; i++) {
				let e = columnEntityList[i]
				if (e.memberHeadData.value.name == this.checkData[memberType]){
					this.type2RowValueListDict.set(memberType,  ExcelService.GetColumnDataList(e) )
				}
			}
		}
	}

	getInitMethodName(){
		return `Init${this.columnEntity.memberHeadData.value.name}Static`
	}

	onWriteCode(generator : TsGenerator, entity : ConfigDataEntity){

		let ret = this.generateWithFile("template",
			{
				initMethod:this.getInitMethodName(),
				type2RowValueListDict : this.type2RowValueListDict,
				valueList : ExcelService.GetColumnDataList(this.columnEntity)
			})
		let methodInfo = new MethodInfo()
		methodInfo.initMethodName = this.getInitMethodName()
		methodInfo.methodContent = ret
		let methodMap = entity.indexInitMethodNameDict.value
		methodMap.set(this.getInitMethodName(), methodInfo)
	}





}